﻿Imports ISNet.WebUI.WebTreeView
Imports System.Data

Partial Class test3
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Response.Write(Now & "<br>")
        PlotNode()
        WebTreeView3.ExpandAll()
        'Response.Write(Now)
    End Sub

    Sub PlotNode()

        Dim MyNode As WebTreeViewNode
        MyNode = New WebTreeViewNode()





        Dim adapter As New FundCenterParentTableAdapters.fctr_viewTableAdapter
        Dim dt As New FundCenterParent.fctr_viewDataTable
        dt = adapter.GetDataByUser(Session("users"), 2014)

        Dim root_id As String
        If dt.Count = 1 Then
            For Each row As FundCenterParent.fctr_viewRow In dt
                MyNode.Text = row.description
                MyNode.Value = row.FundCenterCode
                root_id = row.FundCenterCode

            Next
            WebTreeView3.Visible = False
            Exit Sub
        Else

            MyNode.Text = "GSB"
            MyNode.Value = "0"
            root_id = "0"

        End If






        If dt.Count > 0 Then
            Dim rootpath = ""
            rootpath = FctrClass.GetRoot(Session("users"), 2014)
            Dim rootarr() As String = Split(rootpath, ",")
            WebTreeView3.Nodes.Add(MyNode)

            For i = 0 To rootarr.Length - 1
                PlotChild(rootarr(i), MyNode, 1)
            Next

        End If


    End Sub

    Sub PlotChild(ByVal gpath As String, ByRef cnode As WebTreeViewNode, ByVal level As Decimal)
        'Response.Write(gpath & "<br />")
        Dim Hadapter As New FundCenterParentTableAdapters.FctHTableAdapter
        Dim Hdatatable As New FundCenterParent.FctHDataTable
        Hdatatable = Hadapter.GetDataByGPath(gpath, 2014)

        Dim MyNode As WebTreeViewNode
        MyNode = New WebTreeViewNode()
        For Each row As FundCenterParent.FctHRow In Hdatatable


            MyNode.Text = row.Description
            MyNode.Value = row.FundCenter_FundCenterCode

            cnode.Nodes.Add(MyNode)
        Next
        'Hdatatable = Hadapter.GetDataByUserLikeGpath(gpath & "__", Session("users"), Val(Session("PlanYear")))

        Dim pathadd As String = "__"
        'For i = 1 To 4
        '    Dim fullpath As String = gpath & pathadd
        '    Hdatatable = Hadapter.GetDataByUserLikeGpath(fullpath, "bb9140", 2014)
        '    If Hdatatable.Count > 0 Then
        '        Exit For
        '    End If
        '    'Response.Write(fullpath & "<br />")
        '    pathadd += "__"
        'Next
        'Response.Write(Hdatatable.Count)
        Dim fullpath As String = gpath & pathadd
        Hdatatable = Hadapter.GetDataByUserLikeGpath(fullpath, Session("users"), 2014)
        For Each row As FundCenterParent.FctHRow In Hdatatable
            If Len(row.grouppath) < 10 Then
                PlotChild(row.grouppath, MyNode, level + 1)
            End If

        Next



    End Sub

End Class
